home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000154 / patchSG0000154.idb / usr / share / src / OpenGL / exts / oglinfo.c.z / oglinfo.c
Encoding:
C/C++ Source or Header  |  1995-06-12  |  4.2 KB  |  174 lines

  1. #include <GL/glx.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <stdio.h>
  5.  
  6. int visual_request[] = { None }; /* don't need much of a visual */
  7.  
  8. main(int argc, char **argv)
  9. {
  10.   char *display_name = NULL;
  11.   const GLubyte *string;
  12.   Display       *dpy;
  13.   int           screen_num;
  14.   int           major, minor;
  15.   int           dontcare; /* for returned arguments we don't care about */
  16.   XVisualInfo   *vis;
  17.   GLXContext    ctx;
  18.   Window        root,  win;
  19.   Colormap      cmap;
  20.   XSetWindowAttributes swa;
  21.   XEvent        event;
  22.  
  23.   /* parse arguments */
  24.   if(argc > 1)
  25.     if(!strcmp(argv[1],"-display"))
  26.       display_name = argv[2];
  27.     else {
  28.       fprintf(stderr, "Usage: %s [-display <display>]\n",argv[0]);
  29.       return -1;
  30.     }
  31.  
  32.   /* get display */
  33.   if (!(dpy = XOpenDisplay(display_name))) {
  34.     fprintf(stderr,"Error: XOpenDisplay() failed.\n");
  35.     return -1;
  36.   }
  37.  
  38.   /* does the server know about OpenGL & GLX? */
  39.   if(!XQueryExtension(dpy, "GLX", &dontcare, &dontcare, &dontcare)) {
  40.     fprintf(stderr,"This system doesn't appear to support OpenGL\n");
  41.     return -1;
  42.   }
  43.     
  44.  
  45.   /* find the glx version */
  46.   if(glXQueryVersion(dpy, &major, &minor))
  47.     printf("GLX Version: %d.%d\n", major, minor);
  48.   else {
  49.     fprintf(stderr, "Error: glXQueryVersion() failed.\n");
  50.     return -1;
  51.   }
  52.  
  53.   /* get screen number */
  54.   screen_num = DefaultScreen(dpy);
  55.  
  56. /* This #ifdef isn't redundant. It keeps the build from breaking
  57. ** if you are building on a machine that has an old (1.0) version
  58. ** of glx.
  59. **
  60. ** This program could still be *run* on a machine that has an old 
  61. ** version of glx, even if it was *compiled* on a version that has
  62. ** a new version.
  63. **
  64. ** If compiled on a system with an old version of glx, then it will 
  65. ** never recognize glx extensions, since that code would have been
  66. ** #ifdef'ed out.
  67. */
  68. #ifdef GLX_VERSION_1_1
  69.  
  70.   /*
  71.   ** This test guarantees that glx, on the display you are inquiring,
  72.   ** suppports glXQueryExtensionsString().
  73.   */
  74.   if(minor > 0 || major > 1)
  75.     string = glXQueryExtensionsString(dpy, screen_num);
  76.   else
  77.     string = "";
  78.  
  79.   if(string)
  80.     printf("GLX Extensions (client & server): %s\n",
  81.        string);
  82.   else {
  83.     fprintf(stderr, "Error: glXQueryExtensionsString() failed.\n");
  84.     return -1;
  85.   }
  86.  
  87. #endif
  88.  
  89.    /* get any valid OpenGL visual */
  90.    if (!(vis = glXChooseVisual(dpy, screen_num, visual_request)))  {
  91.      fprintf(stderr,"Error: glXChooseVisual() failed.\n");
  92.      return -1;
  93.      }
  94.  
  95.    /* get context */
  96.    ctx = glXCreateContext(dpy,vis,0,GL_TRUE);
  97.  
  98.    /* root window */
  99.    root = RootWindow(dpy,vis->screen);
  100.  
  101.    /* get RGBA colormap */
  102.    cmap = XCreateColormap(dpy, root, vis->visual, AllocNone);
  103.  
  104.    /* get window */
  105.    swa.colormap = cmap;
  106.    swa.border_pixel = 0;
  107.    swa.event_mask = StructureNotifyMask;
  108.    win = XCreateWindow(dpy, root, 0, 0, 1, 1, 0, vis->depth,
  109.                InputOutput,vis->visual,
  110.                CWBorderPixel|CWColormap|CWEventMask,
  111.                &swa);
  112.  
  113.    glXMakeCurrent(dpy,win,ctx);
  114.  
  115.   string = glGetString(GL_VERSION);
  116.   if(string)
  117.     printf("OpenGL Version: %s\n", string);
  118.   else {
  119.     fprintf(stderr, "Error: glGetString(GL_VERSION) failed.\n");
  120.     return -1;
  121.   }
  122.  
  123.   string = glGetString(GL_EXTENSIONS);
  124.  
  125.   if(string)
  126.     printf("OpenGL Extensions: %s\n", string);
  127.   else {
  128.     fprintf(stderr, "Error: glGetString(GL_EXTENSIONS) failed.\n");
  129.     return -1;
  130.   }
  131.  
  132. /*
  133. ** This #ifdef prevents a build failure if you compile on an a
  134. ** machine with an old GLU library. 
  135. **
  136. ** If you build on a pre GLU 1.1 machine, you will never be able
  137. ** to get glu info, even if you run on a GLU 1.1 or latter machine,
  138. ** since the code has been #ifdef'ed out.
  139. */
  140. #ifdef GLU_VERSION_1_1
  141.  
  142.   /*
  143.   ** If the glx version is 1.1 or latter, gluGetString() is guaranteed
  144.   ** to exist.
  145.   */
  146.   if(minor > 0 || major > 1)
  147.     string = gluGetString(GLU_VERSION);
  148.   else
  149.     string = "1.0";
  150.  
  151.   if(string)
  152.     printf("GLU Version: %s\n", string);
  153.   else {
  154.     fprintf(stderr, "Error: gluGetString(GLU_VERSION) failed.\n");
  155.     return -1;
  156.   }
  157.   
  158.   if(minor > 0 || major > 1)
  159.     string = gluGetString(GLU_EXTENSIONS);
  160.   else
  161.     string = "";
  162.  
  163.   if(string)
  164.     printf("GLU Extensions: %s\n", string);
  165.   else {
  166.     fprintf(stderr, "Error: gluGetString(GLU_EXTENSIONS) failed.\n");
  167.     return -1;
  168.   }
  169.  
  170.  
  171. #endif
  172.  
  173. }
  174.